library(tidyverse)
library(readxl)
path = "files/2025-06-08/Challenge 31.xlsx"
input = read_excel(path, range = "B3:D9")
test = read_excel(path, range = "F3:G5")
result = input %>%
pivot_longer(cols = -c(1), names_to = "Store", values_to = "Fruit Sale") %>%
mutate(count = 1) %>%
summarise(count = sum(count, na.rm = T), .by = c("Store", "Fruit Sale")) %>%
unite("Fruits Sale", c("Fruit Sale", "count"), sep = ": ") %>%
summarise(
`Fruits Sale` = paste(`Fruits Sale`, collapse = ", "),
.by = "Store"
)
all.equal(result, test)
# [1] TRUECrispo - Excel Challenge 23 2025
excel-challenges
weekly-exercises
Easy Sunday Excel Challenge

Challenge Description
Easy Sunday Excel Challenge
⭐ ⭐Count and Merge Sales into one field ⭐Join the count using a comma
Solutions
Logic:
Reads the workbook range needed for the challenge
Reshapes the data to the grain required by the task
Aggregates or ranks values at the correct grouping level
Builds the intermediate helper columns that drive the final answer
Strengths:
- The R solution stays compact and mirrors the workbook logic closely.
Areas for Improvement:
- The code assumes the workbook layout and named ranges remain stable.
Gem:
- The best part of the solution is choosing a tidy intermediate shape before producing the final answer.
import pandas as pd
path = "files/2025-06-08/Challenge 31.xlsx"
input = pd.read_excel(path, usecols="B:D", skiprows=2, nrows=7)
test = pd.read_excel(path, usecols="F:G", skiprows=2, nrows=2)
df = input.melt(id_vars=input.columns[0], var_name="Store", value_name="Fruit Sale")
df["count"] = 1
grouped = df.groupby(["Store", "Fruit Sale"], dropna=False, as_index=False)["count"].sum()
grouped["Fruits Sale"] = grouped["Fruit Sale"].astype(str) + ": " + grouped["count"].astype(str)
result = grouped.groupby("Store", as_index=False)["Fruits Sale"].apply(lambda x: ", ".join(x)).reset_index(drop=True)
print(result.equals(test))
# Semantically result the same, different order of fruits.Logic:
Reads the workbook range needed for the challenge
Reshapes the data to the grain required by the task
Aggregates or ranks values at the correct grouping level
Strengths:
- The Python version keeps the same rule in a direct pandas-oriented workflow.
Areas for Improvement:
- As with the R version, any workbook layout change would require small adjustments.
Gem:
- The implementation stays close to the stated challenge instead of adding unnecessary complexity.
Difficulty Level
This task is moderate:
It combines familiar Excel-style logic with at least one non-trivial reshape, grouping, or parsing step.
The answer depends on getting the output layout exactly right.